package com.hot100.easy;

import java.util.ArrayList;
import java.util.List;
import java.util.Stack;

/**
 * @ClassName Demo06
 * @Description 中序遍历
 * @Author zt
 * @Date 15:29 2022/6/9
 * @Version 1.0
 **/
public class Demo06 {


    public static void main(String[] args) {

    }

    public List<Integer> inorderTraversal(TreeNode root) {
        List<Integer> list=new ArrayList<>();
        Stack stack=new Stack();
        while (!stack.empty()||root!=null){
            if (root!=null){
                stack.push(root);
                root=root.left;
            }else {
                root= (TreeNode) stack.pop();
                list.add(root.val);
                root=root.right;
            }
        }
        return list;
    }

    /**
     * Definition for a binary tree node.
     * *
     *
     */
    public class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode() {
        }

        TreeNode(int val) {
            this.val = val;
        }

        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }
}